<?php
class C_main extends Nvl_Controller{
	function __construct(){
		parent::__construct();
		session_start();
		if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
			if(!isset($_SESSION[SESSION_USERID])){
				$this->output->set_status_header('301');
			}
		}else{
			if(!isset($_SESSION[SESSION_USERID])){
				$this->session->set_flashdata(EXPIRED_SESSION);
				redirect('c_login');
			}
		}
		$this->load->model('m_main');
	}
	
	function create_menu( $arr , $parent=false){
		$html = ($parent==false) ? "\n<ul>\n" : "\n<ul class='sub'>\n";
		foreach ($arr as $key=>$v){
			$html .= '<li>';
			$html .= '<a href="#" pages="'. $v['menu_link'] .'" nama="'. $v['menu_nama'] .'">';
			$html .= '<span class="icon16 '. (($v['menu_icon'] == '') ? 'icomoon-icon-file' : $v['menu_icon']) .'"></span>'. $v['menu_nama'];
			$html .= '</a>';
			if (array_key_exists('children', $v)){
				$html .= $this->create_menu($v['children'], true);
			}
			$html .= '</li>';
		}
		$html .= "</ul>\n";
		return $html;
	}
	
	function index(){
		$list_menu=$this->m_main->get_menus();
		$data['menus']=$this->create_menu($list_menu);
		$this->load->view('main_page', $data);
	}
	
	function welcome(){
		$this->load->view('pages/v_welcome');
	}
}